#include <QWidget>

#include "tabwidget.h"
#include "myview.h"

tabWidget::tabWidget(QWidget *parent = 0)
{
    setMovable(true);
    setTabsClosable(true);
//    singleTab *stab=new singleTab(this->manager);
}

void tabWidget::createTabForURL(QUrl url, QIcon icon, QString label)
{
}

myWebView *tabWidget::webView(int index) const
{
    QWidget *widget = this->widget(index);
    if (myWebView *mywebView = qobject_cast<myWebView*>(widget)) {
        return mywebView;
    } else {
        // optimization to delay creating the first webview
/*
        if (count() == 1) {
            tabWidget *that = const_cast<tabWidget*>(this);
            that->setUpdatesEnabled(false);
            that->newTab();
            that->chiuditab(0);
            that->setUpdatesEnabled(true);
            return currentWebView();
        }
*/
    }
    return 0;
}

void tabWidget::chiuditab(int index)
{
    if (index < 0)
        index = currentIndex();
    if (index < 0 || index >= count())
        return;
    removeTab(index);
}

myWebView *tabWidget::currentWebView() const
{
    return webView(currentIndex());
}

myWebView *tabWidget::newTab(bool makeCurrent)
{
//*
    myWebView *webView = new myWebView();
    addTab(webView, tr("LE POPPE"));
    return webView;
//*/
    //return currentWidget();
}

bool tabWidget::noTabsOn()
{
}

int tabWidget::findMatchingTab(QUrl url)
{
}

// aggiungitab ONLY IF NOT ON ALREADY
void tabWidget::aggiungitab(QUrl url,QIcon icon,QString label)
{
}

void tabWidget::aggiornatab(int index)
{
}

void tabWidget::aggiornatabtip(QUrl url)
{
}
